	var x = document.cookie;

		function Cookie(){
			$.post("http://localhost:8080/Prodavalnik/CookieServlet",{'cookies':x},
					function(data){
					var values= data.split(',');
					$.post("http://localhost:8080/Prodavalnik/LoginServlet",{'name':values[0],'password':values[1],
						'existCookie':values[2]},
						function(data){
							if(data=="true"){
								document.getElementById("username").value = values[0];
								document.getElementById("password").value = values[1];
							}
						}
					)
				}
			)
		} 
		
		 	function addCategories(){
		 		$.get("http://localhost:8080/Prodavalnik/getCategory?name=root",function(data){
		 			var values=data.split('!');
		 			$('#Categories').empty().html(values[0]);
		 			$('#CategoriesMenu').html(values[1]);
		 	});
		 	}
		 	
		 	

	function All(){
		 		addCategories();
		 		Cookie();
		 		
		 	}
		 function nextSubCategory(id,data){
		 		var html = $('#'+id).html();
		 		$.get("http://localhost:8080/Prodavalnik/getCategory?name=root",function(rootData){
	 				if(rootData.indexOf("id='"+id+"'")>-1){
	 					var values=rootData.split('!');
		 			$('#CategoriesMenu').html(values[1]);
	 				}	
	 					
	 			});
		 		$.get("http://localhost:8080/Prodavalnik/getCategory?name="+data,function(data1){
		 			
		 			var values=data1.split('!');
		 			//alert(html + "\n" + values[1]);			var start = values[1].indexOf("id='");
		 			var nextString=values[1].substr(values[1].indexOf("id='")+4,10);
		 			var exist = nextString.substr(0,nextString.indexOf("'"));
		 			
		 			if(data1.indexOf("id")==-1)
		 			{
		 				$.get("http://localhost:8080/Prodavalnik/getProducts?categoryID="+data,function (data){
		 					$('#Products').html(data);
		 				});	
		 			}
		 		
					if(html.indexOf(exist)>-1)
		 			{
						$('#'+id).find('ul').remove();
		 			}
		 		
		 				
		 			else{
		 				$('#'+id).html(html + values[1]);
		 			}
		 		}
		 		);
		 	}
		 
		 
	